import { Inject, Controller, Get, Post, Body, Query } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { WxService } from '../service/wx.service';

@Controller('/wx-api')
export class WxController {
  @Inject()
  ctx: Context;

  @Inject()
  wxService: WxService;

  @Post('/login')
  async login(
    @Body('js_code')
    js_code: string
  ) {
    return await this.wxService.wxAppLogin(js_code);
  }

  @Get('/login')
  async login_get(
    @Query('js_code')
    js_code: string
  ) {
    return await this.wxService.wxAppLogin(js_code);
  }

  @Get('/access_token')
  async getAccessToken() {
    return await this.wxService.getWxAccessToken();
  }

  @Post('/user_phone')
  async getUserPhoneNumber_post(
    @Body('js_code')
    js_code: string
  ) {
    return await this.wxService.getUserPhoneNumber(js_code);
  }

  @Get('/user_phone')
  async getUserPhoneNumber_get(
    @Query('js_code')
    js_code: string
  ) {
    return await this.wxService.getUserPhoneNumber(js_code);
  }
}
